019-remove-nth-node-from-end-of-list.py
problem: ---
problem:

Given a linked list, remove the n-th node from the end of list and return its head.

Example:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.

Note:
Given n will always be valid.

Follow up:
Could you do this in one pass?
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
Replace `p1,p2 = head,head.next` with `p1,p2 = head,head` on line 3.
Add a colon to the if-condition on line 8.
Add a return statement on line 13 to `return head`.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:
On line 3, p2 starts from the second node in the linked list. This could result in a runtime error as the (n+1)st node could be accessed. Instead, set p2 to head.
On line 8, the if-condition has no colon. This is a syntactial mistake that results in a runtime error as the if-condition is not terminated. Adding a colon at the end will fix the mistake.
On line 13, or after line 12, there is no return statement from the method. This results in incorrect behavior. It can be fixed by returning head from the method.
---

-----------------------------------------------------------------------
line_no: ---
line_no:
3
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution(object):
2.     def removeNthFromEnd(self, head, n):
3.         p1,p2 = head,head.next
4.         if not head:
5.             return head
6.         for i in range(n):
7.             p1 = p1.next
8.         if not p1
9.             return p2.next
10.         while p1.next != None:
11.             p1 = p1.next
12.             p2 = p2.next
13.         p2.next = p2.next.next
14.         
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution(object):
2.     def removeNthFromEnd(self, head, n):
3.         p1,p2 = head,head
4.         if not head:
5.             return head
6.         for i in range(n):
7.             p1 = p1.next
8.         if not p1:
9.             return p2.next
10.         while p1.next != None:
11.             p1 = p1.next
12.             p2 = p2.next
13.         p2.next = p2.next.next
14.         return head
---

-----------------------------------------------------------------------
